package com.rfid.project.service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.rfid.project.model.People;
import com.rfid.project.model.Position;
import com.rfid.project.model.ProjectMilestoneFinishApply;
import com.rfid.project.model.ProjectStakeholderType;

@Service
@Transactional
public class ProcessSourceForProjectMilestoneFinishApply {

	@Autowired
	private ProjectMilestoneFinishApplyService projectMilestoneFinishApplyService;

	@Autowired
	private PeopleService peopleService;

	public List<Process> getCurrentQualityListByProcessor(People people) {
		List<Process> resultList = new ArrayList<Process>();
		List<ProjectMilestoneFinishApply> projectMilestoneFinishApplies = null;
		if (people.getPosition().getId().equals(Position.QUALITY_ID)) {
			// 如果当前用户为质量控制岗，则查询所有状态为提交的项目节点完结申请
			projectMilestoneFinishApplies = projectMilestoneFinishApplyService.findByStatus(people, ProjectStakeholderType.DEPT_QUALITY, ProcessStatus.FINISH_APPLY, "Y");
		}
		if (projectMilestoneFinishApplies != null && !projectMilestoneFinishApplies.isEmpty()) {
			for (ProjectMilestoneFinishApply projectMilestoneFinishApply : projectMilestoneFinishApplies) {
				Process processTask = new Process();
				processTask.setBizId(projectMilestoneFinishApply.getId());
				processTask.setSubmitPerson(projectMilestoneFinishApply.getApplyPerson());
				processTask.setSubmitTime(projectMilestoneFinishApply.getApplyTime());
				processTask.setProcessStatusId(projectMilestoneFinishApply.getStatus());
				processTask.setProcessTypeId(ProcessType.PROJECT_MILESTONE_QUALITY);
				processTask.setProcessTitle(projectMilestoneFinishApply.getProjectMilestone().getProject()
						.getName() +"_"+ projectMilestoneFinishApply.getProjectMilestone().getName() + "_申请完结!");
				resultList.add(processTask);
			}
		}
		return resultList;
	}

	public List<Process> getCurrentTaskListByProcessor(People people) {
		List<Process> resultList = new ArrayList<Process>();
		List<ProjectMilestoneFinishApply> projectMilestoneQualityFinishApplies = null;
		List<ProjectMilestoneFinishApply> projectMilestoneFinishApplies = null;
		if (people.getPosition().getId().equals(Position.PLAN_ID)) {
			// 如果当前用户为计划调度岗，则查询所有状态为质量合格的项目节点完结申请
			projectMilestoneQualityFinishApplies = projectMilestoneFinishApplyService.findByStatus(people, ProjectStakeholderType.DEPT_PLAN, ProcessStatus.QUALITY_SUCCESS, "Y");
			projectMilestoneFinishApplies = projectMilestoneFinishApplyService.findByStatus(people, ProjectStakeholderType.DEPT_PLAN, ProcessStatus.FINISH_APPLY, "N");
		}
		if (null != projectMilestoneQualityFinishApplies && !projectMilestoneQualityFinishApplies.isEmpty()) {
			for (ProjectMilestoneFinishApply projectMilestoneFinishApply : projectMilestoneQualityFinishApplies) {
				Process processTask = new Process();
				processTask.setBizId(projectMilestoneFinishApply.getId());
				processTask.setSubmitPerson(projectMilestoneFinishApply.getApplyPerson());
				processTask.setSubmitTime(projectMilestoneFinishApply.getApplyTime());
				processTask.setProcessStatusId(projectMilestoneFinishApply.getStatus());
				processTask.setProcessTypeId(ProcessType.PROJECT_MILESTONE_FINISH);
				processTask.setProcessTitle(projectMilestoneFinishApply.getProjectMilestone().getProject()
						.getName() +"_"+ projectMilestoneFinishApply.getProjectMilestone().getName() + "_申请完结!");
				resultList.add(processTask);
			}
		}
		if (null != projectMilestoneFinishApplies && !projectMilestoneFinishApplies.isEmpty()) {
			for (ProjectMilestoneFinishApply projectMilestoneFinishApply : projectMilestoneFinishApplies) {
				Process processTask = new Process();
				processTask.setBizId(projectMilestoneFinishApply.getId());
				processTask.setSubmitPerson(projectMilestoneFinishApply.getApplyPerson());
				processTask.setSubmitTime(projectMilestoneFinishApply.getApplyTime());
				processTask.setProcessStatusId(projectMilestoneFinishApply.getStatus());
				processTask.setProcessTypeId(ProcessType.PROJECT_MILESTONE_FINISH);
				processTask.setProcessTitle(projectMilestoneFinishApply.getProjectMilestone().getProject()
						.getName() +"_"+ projectMilestoneFinishApply.getProjectMilestone().getName() + "_申请完结!");
				resultList.add(processTask);
			}
		}
		return resultList;
	}

	public List<Process> getCurrentTaskListByCreator(Long userId) {
		// TODO Auto-generated method stub
		return null;
	}

	public List<Process> getHistoryTaskListByProcessor(Long userId) {
		// TODO Auto-generated method stub
		return null;
	}

	public List<Process> getHistoryTaskListByCreator(Long userId) {
		// TODO Auto-generated method stub
		return null;
	}
}
